Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(e2e): setup zrc20 in one transaction #3077

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Oct 31, 2024

Description

Deploy zrc20 contracts in one transaction to increase e2e setup speed. This reduces setup time by ~20 seconds. Also:

  • automatically increase gas limit and fees if multiple messages are provided to broadcast
  • return error immediately if broadcast or transaction fails (code != 0)

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Enhanced transaction handling with support for broadcasting multiple messages in a single transaction.
    • Introduced batch deployment for ZRC20 contracts, allowing for more efficient contract management.
    • New methods added for enabling header verification, updating gateway addresses, deploying system contracts, funding emissions pools, and updating keygen.
  • Bug Fixes

    • Improved error handling in transaction broadcasting to manage failures more effectively.
  • Refactor

    • Updated method names and signatures for better clarity and functionality, reflecting changes in liquidity cap management.

@gartnera gartnera added no-changelog Skip changelog CI check UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light labels Oct 31, 2024
Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications primarily to the localE2ETest function in cmd/zetae2e/local/local.go, enhancing the control flow by adding a conditional block for setup steps based on the skipSetup flag. Additionally, the TestWhitelistERC20 function in e2etests/test_whitelist_erc20.go sees a method name change reflecting an update in liquidity cap handling. Significant changes in e2e/txserver/zeta_tx_server.go include method signature updates to support multiple transactions and a restructuring of deployment logic for ZRC20 tokens, alongside new methods for enhanced functionality.

Changes

File Path Change Summary
cmd/zetae2e/local/local.go Modified localE2ETest to add a conditional block for setup steps based on skipSetup. Adjusted logic for waiting on keygen completion.
e2e/e2etests/test_whitelist_erc20.go Renamed method call from InitializeLiquidityCap to InitializeLiquidityCaps in TestWhitelistERC20.
e2e/txserver/zeta_tx_server.go Updated BroadcastTx to accept variadic messages. Restructured DeployZRC20s for batch deployment. Renamed InitializeLiquidityCap to InitializeLiquidityCaps. Added multiple new methods for various functionalities.

Possibly related PRs

Suggested labels

V2_TESTS

Suggested reviewers

  • fbac
  • skosito
  • kingpinXD
  • ws4charlie
  • lumtis
  • swift1337

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gartnera gartnera marked this pull request as ready for review October 31, 2024 20:19
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
e2e/e2etests/test_whitelist_erc20.go (1)

Line range hint 1-124: Architecture feedback for test structure.

While the test is comprehensive, consider these architectural improvements:

  1. Extract the ERC20 deployment and whitelisting into helper functions to improve reusability across other tests
  2. Consider using test fixtures for the ERC20/ZRC20 setup and cleanup

Would you like me to provide an example of how to refactor this using test fixtures?

e2e/txserver/zeta_tx_server.go (1)

Line range hint 196-218: Consider using gas estimation instead of scaling gas and fees linearly with message count.

Multiplying the gas limit and fees by the number of messages may not accurately reflect the actual gas usage and required fees for the transaction. Consider using gas estimation to calculate the appropriate gas limit and fee amount for the batched messages. This approach can improve efficiency and reduce the likelihood of transaction failures due to insufficient gas.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 146f443 and f244f94.

📒 Files selected for processing (3)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/e2etests/test_whitelist_erc20.go (1 hunks)
  • e2e/txserver/zeta_tx_server.go (8 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
cmd/zetae2e/local/local.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/e2etests/test_whitelist_erc20.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/txserver/zeta_tx_server.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (5)
e2e/e2etests/test_whitelist_erc20.go (1)

53-54: Method signature change looks good.

The update from InitializeLiquidityCap to InitializeLiquidityCaps aligns with the PR's objective of optimizing the setup process by handling multiple transactions efficiently.

Let's verify this API change is consistently applied across the codebase:

✅ Verification successful

Let me gather more information using different search patterns to verify this API change thoroughly.


API change verification complete - Implementation is consistent

The method change from InitializeLiquidityCap to InitializeLiquidityCaps has been properly implemented:

  • The implementation exists in e2e/txserver/zeta_tx_server.go with correct variadic parameter support
  • No instances of the old singular method name remain in the codebase
  • The method is properly documented and includes error handling
  • The test usage in test_whitelist_erc20.go correctly aligns with the implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the old method name is not used anywhere else
# and the new method is properly implemented

# Test 1: Check for any remaining usage of old method name
echo "Checking for old method name usage..."
rg "InitializeLiquidityCap[^s]"

# Test 2: Verify the new method implementation
echo "Verifying new method implementation..."
ast-grep --pattern 'func $_($$) InitializeLiquidityCaps($$$)'

Length of output: 269


Script:

#!/bin/bash
# Search for any InitializeLiquidityCap variations more broadly
echo "Searching for InitializeLiquidityCap variations..."
rg -i "initializeliquiditycap" -A 2

# Search for interface or struct definitions containing this method
echo "Searching for interface/struct definitions..."
ast-grep --pattern 'type $_ interface {
  $$$
  InitializeLiquidityCaps($$$)
  $$$
}'

# Search for the actual implementation
echo "Searching for method implementations..."
ast-grep --pattern 'func ($_ $_) InitializeLiquidityCaps($$$) {
  $$$
}'

Length of output: 1275

cmd/zetae2e/local/local.go (1)

Line range hint 192-196: Validate keygen status even when setup is skipped.

The current implementation assumes keygen is completed when setup is skipped. This assumption could lead to issues if incorrect. Consider adding a validation check.

-if !skipSetup {
+// Always verify keygen status, but only wait for completion during setup
+resp, err := deployerRunner.ObserverClient.Keygen(ctx, &observertypes.QueryGetKeygenRequest{})
+noError(err)
+if resp.Keygen == nil || resp.Keygen.Status == observertypes.KeygenStatus_PendingKeygen {
+  if !skipSetup {
     waitKeygenHeight(ctx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 10)
+  } else {
+    logger.Print("⚠️ Warning: Keygen is pending but setup is skipped")
+  }
 }
e2e/txserver/zeta_tx_server.go (3)

244-246: Properly handling broadcast failures when the transaction code is non-zero.

Good addition to catch and handle transaction failures based on the response code. This ensures that errors are reported immediately, enhancing the robustness of the transaction broadcasting process.


271-273: Consistent error handling for transaction failures based on result code.

Appropriate inclusion of error checking for resTx.TxResult.Code. This consistency in error handling improves the reliability of the transaction process.


598-611: Efficiently initializing liquidity caps for multiple ZRC20 tokens in a single transaction.

This refactoring improves performance by batching the initialization of liquidity caps, reducing transaction overhead and network load. Well-implemented and aligns with best practices for efficient batch processing.

cmd/zetae2e/local/local.go Show resolved Hide resolved
e2e/txserver/zeta_tx_server.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli no-changelog Skip changelog CI check UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants